import numpy as np
import csv
import random
from datetime import datetime
import math as math
import matplotlib.pyplot as plt

def getCurTime():
    """
    get current time
    Return value of the date string format(%Y-%m-%d %H:%M:%S)
    """
    format='%Y-%m-%d %H:%M:%S'
    sdate = None
    cdate = datetime.now()
    try:
        sdate = cdate.strftime(format)
    except:
        raise ValueError
    return sdate

def cal_bernoulli_likelihood_ratio(iObZ, iObT, iPopZ, iPopT):
    # iObZ: the observed number in the certain Zone, e.g. the number of cancer cases in a region
    # iObT: the total observed number, e.g. the total number of cancer cases
    # iPopZ: the population in the certain Zone 
    # iPopT: the total population
    # return the natural logarithm of ratio
    temp_lambda = 0.0
    temp_z_p = (0.0 + iObZ)/iPopZ
    temp_out_p = (0.0 + iObT - iObZ)/(iPopT - iPopZ)
    temp_t_p = (0.0 + iObT)/iPopT
    if temp_z_p > temp_out_p:
        #temp_denominator = temp_t_p ** int(iObT)
        #temp_numerator = (temp_z_p**int(iObZ))*(temp_out_p**int(iObT - iObZ))
        #temp_lambda = temp_numerator/temp_denominator
        temp_lambda = iObZ * math.log(temp_z_p) + (iPopZ - iObZ) * math.log(1 - temp_z_p) +\
                        (iObT - iObZ)* math.log(temp_out_p) + ((iPopT - iPopZ) - (iObT - iObZ))* math.log(1 - temp_out_p) \
                        - iObT * math.log(temp_t_p) - (iPopT - iObT) * math.log(1 - temp_t_p)
    return temp_lambda

def cal_poisson_likelihood_ratio(iObZ, iObT, iPopZ, iPopT):
    # iObZ: the observed number in the certain Zone, e.g. the number of cancer cases in a region
    # iObT: the total observed number, e.g. the total number of cancer cases
    # iPopZ: the population in the certain Zone 
    # iPopT: the total population
    # return the natural logarithm of ratio
    temp_lambda = 0.0
    temp_z_p = (0.0 + iObZ)/iPopZ
    temp_out_p = (0.0 + iObT - iObZ)/(iPopT - iPopZ)
    temp_t_p = (0.0 + iObT)/iPopT
    #print temp_out_p
    #temp_lambda = iObZ * math.log(temp_z_p) + (iObT - iObZ)* math.log(temp_out_p) - iObT * math.log(temp_t_p)
    if temp_z_p > temp_out_p:
        temp_lambda = iObZ * math.log(temp_z_p) + (iObT - iObZ)* math.log(temp_out_p) - iObT * math.log(temp_t_p)
    '''
    print temp_z_p
    print math.log(temp_z_p)
    print math.log(temp_out_p)
    print math.log(temp_t_p)
    '''
    return temp_lambda

#--------------------------------------------------------------------------
#MAIN

if __name__ == "__main__":
    print "begin at " + getCurTime()
    contiguityCSV = ''
    c1 = 1713
    ct = 6000
    p1 = 7627173
    pt =  29535210
    print c1, ct, p1, pt, cal_poisson_likelihood_ratio(c1, ct, p1, pt)
    #iObZ = [9.159925636005937, 4.608663375140168, 1.997310492224642, 15.62904079828877, 3.714585143708973, 2.720513663312886, 5.815723527222872, 5.3498454852961, 0.9919575492676813, 0.8085052097158041, 5.471641100128181, 3.8863006767933257, 16.18400651263073, 6.376223754952662, 3.171401905536186, 3.6368444218533114, 3.950553381786449, 21.592530636058655, 12.810890993161593, 5.9611882518511266, 9.745974295947235, 11.09765283903107, 4.9323737808008445, 3.5969769448274747, 4.76950678465073, 2.7687525958754122, 6.355432537209708, 3.5445047795656137, 4.188108798058238, 27.010180018114625, 0.7395177313010208, 7.74788886832539, 3.750870964868227, 11.886065949685872, 12.693249238829594, 15.82811884014518, 7.935923554759938, 8.195812348276377, 5.8659622395935, 8.306106214004103, 3.957039943576092, 7.777884674724191, 23.473692365543684, 5.145220930426149, 7.484163382672705, 23.184672632676666, 5.4716339679434896, 36.32865683734417, 8.323507126857294, 7.54380407743156, 14.557787358644418, 16.82452237830148, 5.9722421138576465, 66.89452366539626, 2.998167907135212, 29.012073218938895, 13.684142858532141, 7.895281265227823, 149.23374285674072, 77.0345311069832, 15.467131398036145, 3.923993402859196, 5.73398991706199, 4.155192773832823, 58.739676488912664, 48.79399267095141, 36.796949130744906, 50.95334183075465, 21.796069812378846, 47.894143430748954, 24.946305022051092, 18.29546717037738, 16.746726746307104, 85.41896881826688, 12.568420916810283, 11.12334558845032, 3.2200505128275836, 66.12009161355672, 3.358512683189474, 5.161557358005666, 16.978969049087027, 23.90607198170619, 8.401283744708053, 81.16028276344878, 2.979840517306002, 12.104604105479666, 14.597018683038186, 79.75004109728616, 23.331575105024967, 24.310831122274976, 3.5193536877050065, 7.307479102601064, 0.38771160834585316, 0.4561189063824713, 2.1096741983346874, 11.873402563040145, 0.6606541411019862, 7.68105042600655, 17.951141987519804, 3.943834454694297, 1.3981868233531713, 5.545812880445737, 36.37414149928372, 0.3370960554748308, 4.915496321773389, 90.80999532273563, 14.354099298245274, 26.830605999857653, 6.185311275621643, 13.976883064111462, 9.037705174167058, 10.441536898724735, 54.625954869625275, 8.090056118206121, 18.25153372049681, 8.395304614969064, 1.5090239527635276, 3.273140842851717, 6.217884482903173, 12.45909016742371, 96.40415777548333, 10.239862542948686, 50.00500229530735, 22.372427831869572, 14.257736584550003, 136.8490639416268, 10.932639420032501, 137.57593307259958, 96.36869486013893, 3.695523171540117, 173.44468030019198, 23.682958897494245, 5.746929233078845, 64.47038237725792, 212.29419798828894, 26.962156502646394, 10.033809544023825, 140.27718615112826, 26.619665879494278, 15.98998311845935, 4.99089317250764, 252.18748775229324, 22.15957920780056, 58.59047933956026, 2.687104440294206, 29.487894932171912, 44.98497284995392, 169.42916991049424, 17.56157140393043, 45.93023589689983, 3.4701226986944675, 49.31428824420436, 74.31305769458413, 9.66142336979101, 26.174985350633506, 57.89364940254018, 63.34028921846766, 33.61866083704808, 5.0691934584174305, 21.604129612329416, 38.94689885521075, 13.026785389025463, 12.942208020598628, 33.07937114033848, 34.79338218200428, 35.61577007170126, 42.787423387460876, 1.398319784551859, 21.36168001932674, 156.64814100950025, 8.065535134111997, 50.38133058164385, 5.999720782128861, 47.412595527857775, 20.36256732358015, 39.284979482064955, 6.3737979900761275, 19.85091332164302, 11.689843409374589, 8.039646636258112, 6.493007251483505, 4.136822105268948, 17.420845896136598, 10.78690170138725, 69.00632165983552, 12.718422315083444, 13.412719320593169, 2.06900913149002, 10.011721680421033, 16.284421073680278, 70.15790040875436, 8.495049205521354, 2.773521601135144, 41.13756420905702, 2.593223621312063, 71.10131334322796, 11.344737736930256, 4.814625136350514, 4.97825467135408, 10.08002060414583, 4.631103161140345, 9.768875658483012, 8.463063181668986, 4.208378771494608, 3.042106534674531, 8.435979638830759, 8.133968378591817, 2.6802777405828238, 13.733473030442838, 27.920354630361544, 8.620110997930169, 22.66100045730127, 4.185120462716441, 70.31298205704661, 8.754749154963065, 54.47911862045294, 7.882673689222429, 6.09297591377981, 99.84372987539973, 9.31165236576635, 3.0788103220402263, 6.342039378272602, 3.8543863148224773, 5.425000526651274, 2.312878870739951, 4.841317005906603, 9.137186572756036, 8.352944081649184, 13.99079582648119, 1.4000548902986338, 8.852091849825229, 4.675389029260259, 23.576835854299134, 5.34779408313625, 10.238428569864482, 26.872869728249498, 6.842646808130667, 4.006646109322901, 4.7101256642490625, 4.266346001764759, 4.381652287978795, 1.3644876711477991, 9.333326416963246, 82.44401946179278, 65.48461049393518]   

    # kernel
    #iObZ = [9.84423908329336, 5.877294937090483, 2.1236113097984344, 16.836464680032805, 4.358002417866373, 2.8133436481148237, 5.479132428881712, 3.1349907447729493, 0.7812058932613581, 0.6215253732079873, 4.747809593274724, 3.002227919816505, 9.136980891198618, 5.501857126946561, 2.104630813206313, 2.872448126669042, 4.225881785445381, 12.944001759635285, 15.604813014622778, 4.249539634416578, 5.102594282972859, 10.241069808136672, 6.001296826754697, 8.814674856621423, 4.969577997690067, 3.81542363029439, 4.0070341304381145, 3.179337891488103, 2.5134718958870508, 21.03598045007675, 0.6034525016875705, 6.480427653877996, 3.1841417450050358, 6.1800879876245745, 7.897672156279441, 12.53906711624586, 6.20888166311488, 6.852802659559529, 4.102403218741529, 11.540846929710824, 3.3627379465615377, 9.032691549509764, 17.68259324868268, 3.7908717303798767, 5.29111242905492, 23.155231686803745, 4.2362692434107885, 33.513997666945215, 8.033116839666036, 5.023136897943914, 15.73620868686703, 16.38118751491129, 7.09866671502823, 66.23474288688158, 3.7205920302221784, 35.816121614247095, 13.088698718289379, 7.459851699095452, 136.96226514664886, 70.73421479690296, 14.43541546308552, 6.30882088385988, 6.763155320091755, 5.107530699388008, 65.95857818727382, 48.27185349189676, 47.29457222492783, 63.992858715791954, 18.70231899592909, 56.287318430724554, 24.9405191395781, 20.841217112203594, 18.528142731869593, 86.77765253413236, 13.844287610496394, 12.68782900966471, 7.036136765018455, 70.52072023926303, 3.3802268985891715, 5.582803878714913, 19.141293198990752, 27.955279647605494, 9.556109056007699, 85.2126546218351, 2.862140815690509, 13.651786974878632, 15.310406157630496, 82.03561901277862, 22.91144285578048, 30.4569054464082, 2.5481525275681634, 6.213342031769571, 0.5382051569031319, 0.5671615041646874, 2.5722022798872786, 15.257984189491253, 0.7307410961948335, 8.429324419936165, 12.873317202815088, 4.187336972405319, 1.218198330316227, 4.46632950057392, 36.02538117900258, 0.6305114202841651, 4.639387679417268, 93.99092864031263, 12.71468790282961, 28.533692227938445, 7.4509078018018045, 11.476848273159703, 7.186042709479807, 8.525044661946595, 47.63963104574941, 10.812259807338705, 18.885659386985935, 8.74129806063138, 1.9683194165118039, 4.1579806040390395, 6.259184864029521, 10.886419521295466, 89.52078920425265, 8.219457644736394, 41.61360258364584, 23.116683463566005, 18.631529003105243, 130.22552843671292, 9.18798466399312, 132.3939101214928, 80.00649976078421, 4.346899086784106, 152.72342391638085, 20.34151333619957, 4.262158707511844, 54.174462338662124, 201.35325167805422, 31.942990547628142, 10.26432232116349, 136.09387434189557, 23.90169586511911, 12.327065014003892, 4.338598839472979, 235.77192760678008, 15.415106949876645, 46.522845901956316, 2.1050688700197497, 37.745950109892874, 39.225467515178025, 146.65698342618998, 28.587876439240063, 36.430899297993165, 4.220861837267876, 56.795049398278934, 65.86459567397833, 12.776950611005304, 20.990583226201124, 53.96803762651689, 74.40576356893871, 34.21613500198873, 4.759952481181244, 17.542124695319217, 44.22030230794917, 11.943104775622487, 7.5703832458821125, 37.73930435767397, 32.03973634398426, 37.99285446493013, 39.74248445418198, 1.3813866232521832, 14.519422328885412, 175.11279530916363, 7.295262843748787, 60.254563762573525, 4.006842083064839, 52.31210645890678, 24.553321976563893, 46.424826074478915, 6.8529604432260385, 21.872212347225286, 13.62695775507018, 7.962975375179667, 7.74314612839953, 2.623652771464549, 18.714630689442856, 12.409819803593564, 71.6553537355503, 17.422413227614015, 13.740192359677167, 2.044567052886123, 9.86102684904472, 18.88534192838415, 85.14297745273507, 9.31541712845501, 2.7164550769375637, 42.59734161081724, 2.5969265128369443, 75.2756569882622, 12.20320402624202, 3.3355086518567987, 5.126159151492175, 10.36794266779907, 3.03444079910696, 8.911176241526846, 7.409776398155373, 4.25365981948562, 2.495462827908341, 12.253711823490448, 12.288171367807081, 3.018616084009409, 15.143646126089152, 27.554436045189505, 10.52687717601657, 21.059362379965023, 4.336723432381405, 83.31404736277182, 10.115104636119213, 67.98707054377883, 8.560843153507449, 6.9332758211530745, 98.98816039477242, 10.07860529932077, 4.448633929132484, 7.386228137504077, 4.052448362854193, 6.5965327150479425, 3.4992516495112795, 7.3771246388496365, 11.63692043418996, 15.798667967319489, 16.64811701470171, 2.4029092921700794, 9.621077493342455, 8.019070238689892, 29.0727802500478, 6.238554737094091, 11.530844882363454, 35.569739547907375, 8.279885545751313, 4.553235998595483, 6.074242740869522, 4.158560900919838, 5.437820648032357, 1.6644621526793344, 9.674767806194723, 77.7647807153844, 67.21333315069205]
    '''
    iObZ = [8.610827528624213, 5.266192354596569, 2.037318519578548, 15.199453875306062, 3.8512030388228595, 3.14715837300173, 5.747281766030937, 4.777736544463551, 1.1712717818445526, 0.8473587906337343, 5.625428803847171, 3.6079651188338175, 13.188958819082472, 6.478299726441037, 3.1196321773168165, 5.287551922956482, 3.467891139938729, 19.719095194304828, 12.201356850215234, 5.546249947277829, 9.568548341689166, 11.076766873709857, 5.575400213638204, 7.568639632954728, 4.3859236516436795, 3.388390095642535, 6.18225434559281, 3.4708276132005267, 4.434077407262521, 27.573707788717, 0.6606281154381577, 8.242859623627737, 3.507180205633631, 12.64684696693439, 13.140679234522395, 15.788592233351665, 8.671214209025493, 9.212732696905732, 3.883682951302035, 10.791033975838218, 4.199411936526303, 9.094090388971381, 24.830989468639018, 4.383922720517148, 7.766728902468458, 21.543551721668337, 4.538189252009033, 35.52560310048284, 7.980271662774612, 7.365087792277336, 14.496655431139516, 16.937466315415804, 5.482978229993023, 67.771183703735, 3.2019136306189466, 28.896516634500585, 14.20153154284344, 7.650171062996378, 137.67955696173885, 73.76960650508408, 16.4769059070386, 2.8815643425332382, 5.070101498014992, 4.259033835696755, 60.86170674848836, 46.77321433718316, 38.46962132983026, 59.424127772217616, 16.012563411917654, 50.28385031770449, 26.219135129649658, 18.981834367790725, 16.896601598957204, 82.59846377465874, 12.45500939883641, 10.44238902971847, 5.638764059840469, 63.30673123447923, 3.5511085635516793, 5.086326492819353, 17.204431208592723, 25.14659372145252, 8.732646641379688, 83.60970370468567, 2.9293863990315003, 11.647683930277708, 14.502285053502419, 80.36831811920274, 22.592813694674987, 31.332816711787018, 3.6154154908726923, 7.855543323676102, 0.38695762389397714, 0.45843100888305344, 2.851332278602058, 13.25736558996141, 0.6517961807549, 8.066980201663682, 15.024897938012145, 4.150224634184269, 1.2147127374191768, 5.486436500505079, 35.771155044960324, 0.5601648621086497, 5.232414941710886, 91.00930460898962, 15.510566995624686, 28.94792280640104, 6.0637342652189545, 13.268940767127788, 8.567475650299457, 10.617064679972827, 55.129303736423026, 8.644669245259138, 19.420184175367467, 9.023294030193938, 1.667333456192864, 3.20630266884109, 5.453792386106215, 13.361324914963916, 97.31895089976024, 10.365251089388039, 51.5017137369141, 23.259586228989065, 14.157679418785847, 139.95130201685242, 11.201534125953913, 141.94655764332856, 93.96912746923044, 3.122062150883721, 167.11501829963527, 23.68574017903302, 6.183462948014494, 61.16135823982768, 216.46644194360124, 25.591570398537442, 10.014895663014613, 137.568259773514, 25.777020730864024, 17.26534542418085, 5.560263341292739, 259.959130438976, 19.661171621919493, 57.014589718717616, 2.5047233150107786, 29.323015439440496, 46.19210613705218, 170.3549120714888, 20.942292398685822, 42.25358553871047, 3.911513786762953, 51.63733318346203, 76.99678755551577, 9.88807660099701, 26.832388133509085, 59.410915366359404, 64.12706790142693, 33.23477967227518, 6.3705787737853825, 21.251739796658512, 39.01215677484288, 12.867190304488759, 10.735523541690782, 32.08062921324745, 34.4486711955542, 35.20141519146273, 41.24314488386153, 1.3677630054298788, 20.262565257726237, 152.54894274508115, 8.247403179833782, 49.720370346913114, 5.042465084872674, 45.95296210690867, 21.114087381371064, 41.08862398273777, 5.9545944577257615, 20.674667048442643, 11.664881840668386, 10.591327807022026, 7.504894426398096, 4.170878424425609, 18.16374401273788, 10.757358979579294, 70.43751156394137, 13.181802302133292, 12.740076363654225, 1.7083815744845197, 9.28481785338954, 17.181955726642627, 73.09488950445666, 8.518667275711778, 2.8544197996670846, 43.93809654342476, 2.2742501579923555, 76.27285329657025, 11.38052186081768, 4.366326576535357, 5.498716200963827, 10.73310611245688, 4.7753310320549645, 9.820321740407962, 7.933321686112322, 4.676980170072056, 2.833791685552569, 8.365483889938332, 9.738262190949172, 2.8045302350074053, 14.328365789406234, 27.74942223141261, 9.145396258682013, 22.32728920869704, 4.149901736760512, 74.85161943151616, 8.83525147556793, 55.092045717610745, 7.950122531503439, 6.001175474608317, 99.90839471027721, 8.284235286540934, 3.7768903239339124, 6.350497961539077, 3.8452544038009364, 5.237429638640606, 2.3317059207474813, 4.6151554235839285, 8.255370614177082, 8.964074849151075, 14.448517810931662, 1.3790303655405296, 8.894162055541528, 4.798691840900574, 24.097136360607692, 4.984223375082365, 8.984878663904965, 26.06381282088114, 7.163256224244833, 3.9105667972035008, 4.519366478547454, 4.190008001256501, 4.355282134187291, 1.3444237926159985, 9.28775931178825, 76.36615160171641, 61.54781667832867]
    iPopZ = [43129.0, 25317.0, 9515.0, 74484.0, 18021.0, 15039.0, 26792.0, 17879.0, 3273.0, 2675.0, 20236.0, 12198.0, 41690.0, 22589.0, 9909.0, 14188.0, 16786.0, 67742.0, 59996.0, 18054.0, 27994.0, 53984.0, 23929.0, 37985.0, 18695.0, 15475.0, 16529.0, 18130.0, 13001.0, 126158.0, 2623.0, 34088.0, 16970.0, 27564.0, 31973.0, 84366.0, 28915.0, 30660.0, 25097.0, 60860.0, 19617.0, 53560.0, 91831.0, 18445.0, 28076.0, 122579.0, 21181.0, 171468.0, 36283.0, 27200.0, 78730.0, 78227.0, 31645.0, 349445.0, 16295.0, 153764.0, 72259.0, 35885.0, 724455.0, 361725.0, 77090.0, 24010.0, 31969.0, 22135.0, 343324.0, 238416.0, 222914.0, 323730.0, 83709.0, 263308.0, 129428.0, 98067.0, 88749.0, 441868.0, 64389.0, 52428.0, 33815.0, 311666.0, 20260.0, 25185.0, 83965.0, 125053.0, 43719.0, 429266.0, 14267.0, 56355.0, 73177.0, 417676.0, 116596.0, 153033.0, 17858.0, 30745.0, 2319.0, 3021.0, 14339.0, 61638.0, 3040.0, 42409.0, 62469.0, 19387.0, 5990.0, 21610.0, 173148.0, 3046.0, 23915.0, 460539.0, 66294.0, 137290.0, 33154.0, 59682.0, 40591.0, 48960.0, 236499.0, 50866.0, 78207.0, 38310.0, 9398.0, 17492.0, 29370.0, 50712.0, 431146.0, 47450.0, 216722.0, 127152.0, 79165.0, 649720.0, 46848.0, 670066.0, 413108.0, 18742.0, 786178.0, 97614.0, 24138.0, 286003.0, 1024302.0, 151544.0, 54118.0, 677574.0, 122798.0, 69279.0, 21364.0, 1231176.0, 85075.0, 258007.0, 10479.0, 173905.0, 193776.0, 710196.0, 124419.0, 197276.0, 20736.0, 275735.0, 342144.0, 58433.0, 106854.0, 286997.0, 353400.0, 168701.0, 24559.0, 101316.0, 217810.0, 62507.0, 40612.0, 192424.0, 173931.0, 199731.0, 228322.0, 7024.0, 76615.0, 848808.0, 40131.0, 287054.0, 20769.0, 261546.0, 117967.0, 228702.0, 33757.0, 116535.0, 60357.0, 39667.0, 35867.0, 14444.0, 91683.0, 62939.0, 362460.0, 76640.0, 70717.0, 9246.0, 56981.0, 93819.0, 392653.0, 49505.0, 17146.0, 213110.0, 13908.0, 376583.0, 58969.0, 15999.0, 26206.0, 50935.0, 15887.0, 38815.0, 37364.0, 18452.0, 10917.0, 55832.0, 53742.0, 13440.0, 61985.0, 126907.0, 41088.0, 114695.0, 21051.0, 371596.0, 45362.0, 244449.0, 35236.0, 30864.0, 507044.0, 48541.0, 17050.0, 32214.0, 19939.0, 25561.0, 11743.0, 26429.0, 47333.0, 50368.0, 73354.0, 9383.0, 43509.0, 25534.0, 109869.0, 26587.0, 48720.0, 143092.0, 31491.0, 21027.0, 23168.0, 20546.0, 23929.0, 8661.0, 44468.0, 392569.0, 324062.0]
    ct = 10000
    pt = 1000000
    rate = (ct + 0.0)/pt
    output = []
    error_output = []
    error = 0
    
    x = 17
    y = 10
    ct = 6022.429629503604
    pt = 2.953521E7
    for x in range(0,len(iPopZ)):
        c1 = iObZ[x]
        p1 = iPopZ[x]
        a = cal_poisson_likelihood_ratio(c1, ct, p1, pt)
        output.append(a)
    max = -1
    maxid = -1
    i = 0
    for item in output:
        if item > max:
            max = item
            maxid = i
        i += 1
    print maxid, max
    
    x = 0
    for i in range(0,10000):
        p1 = random.randint(600, 100000)
        p2 = random.randint(600, 100000)
        c1 = random.uniform(rate, 0.3) * p1
        c2 = random.uniform(rate, 0.3) * p2
        if (c1 + c2) > ct:
            continue
        #print [c1, p1, c2, p2]
        #c1 = random.randint(60, 140)
        #c2 = random.randint(60, 140)
        a = cal_poisson_likelihood_ratio(c1, ct, p1, pt)
        b = cal_poisson_likelihood_ratio(c2, ct, p2, pt)
        c = cal_poisson_likelihood_ratio(c1 + c2, ct, p1 + p2, pt)
        #d = a
        #if b > a:
            #d = b
        x += 1 
        if (c < b) and (c < a):
            error += 1

            #print [c1, p1, c2, p2, c1/p1, c2/p2, a, b, c]
        #error_output.append([c1, p1, c2, p2, a, b, c])
        #output.append([c1, p1, c2, p2, a, b, c])

    print error, x
    '''

    '''
    output = []
    ct = 1000
    pt = 1000000
    for i in range(0,100):
        c1 = random.randint(-100, 100)
        p1 = random.randint(c1*10, pt)
        a = cal_poisson_likelihood_ratio(c1, ct, p1, pt)
        output.append(a)
    
    plt.plot(output, 'r--')
    plt.show()
    '''
    #error_output = np.array(error_output)
    #error_output.shape = (-1, 7)
    #output = np.array(output)
    #output.shape = (-1, 7)
    #plt.plot(output[:100,4], 'b--')
    #plt.plot(output[:100,5], 'g--')
    #plt.plot(output[:100,6], 'r--')
    
    #plt.show()
    #np.savetxt('C:/LLR/temp2.csv', output, delimiter=',', fmt = '%10.5f')
    #np.savetxt('C:/LLR/temp2_error.csv', error_output, delimiter=',', fmt = '%10.5f')
